import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        name: 'Home',
        redirect: '/login'
    },

        {
        path: '/login', //访问地址
        name: 'Login', //路由名称
        component: _ => import('../views/login') //所对应的组件地址
    },
    {
        path:'/manager',
        name:'manager',
        component:_ => import('../views/manager'),
        children:[
            {
                path:'/home',
                name:'Home',
                component:_ =>import('../views/home'),
                meta:{
                    title:'首页',
                    kepAlive:true,
                    isKerwinRequired:true,
                }

            },
          {
            path:'/user',
            name:'User',
            component:_ =>import('../views/users/user'),
            meta:{
              title:'用户管理',
              kepAlive:true,
                isKerwinRequired:true,
            }
          },
          {
            path:'/house',
            name:'House',
            component:_ =>import('../views/houses/house'),
            meta:{
              title:'房源管理',
              kepAlive:true,
                isKerwinRequired:true,
            }
          },
          {
            path:'/order',
            name:'Order',
            component:_ =>import('../views/orders/order'),
            meta:{
              title:'订单管理',
              kepAlive:true,
                isKerwinRequired:true,
            }
          },
          {
            path:'/info',
            name:'Info',
            component:_ =>import('../views/infos/info'),
            meta:{
              title:'管理授权',
              kepAlive:true,
                isKerwinRequired:true,
            }
          },
          {
            path:'/data',
            name:'data',
            component:_ =>import('../views/data/data'),
            meta:{
              title:'到期通知',
              kepAlive:true,
                isKerwinRequired:true,
            }
          },
            {
                path:'/menu',
                name:'menu',
                component:_ =>import('../views/menu/menu'),
                meta:{
                    title:'菜单管理',
                    kepAlive:true,
                    isKerwinRequired:true,
                }
            },
    
        ]
      },
     
    ]
const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})
// 全局拦截
router.beforeEach((to, from, next) => {
    if (to.meta.isKerwinRequired) {
        // 判断 本地存储中是否token
        if (localStorage.getItem('admin')) {
            // next():不拦截，放行
            next()
        } else {
            next('/login')//跳转到登录页面
        }
    } else {
        next()
    }
})
export default router